﻿
Partial Class _ShopRobot
    Inherits System.Web.UI.Page
    Dim shopArray
    Public Shared Function MD5(ByVal strSource As String, ByVal Code As Int16) As String
        '这里用的是ascii编码密码原文，如果要用汉字做密码，可以用UnicodeEncoding，但会与ASP中的MD5函数不兼容 
        Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(strSource)
        Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash)
        Dim i As Integer
        Select Case Code
            Case 16 '´选择16位字符的加密结果 
                For i = 4 To 11
                    MD5 += Hex(hashvalue(i)).ToLower
                Next
            Case 32 ' ´选择32位字符的加密结果 
                For i = 0 To 15
                    MD5 += Hex(hashvalue(i)).ToLower
                Next
            Case Else ' ´Code错误时，返回全部字符串，即32位字符 
                For i = 0 To hashvalue.Length - 1
                    MD5 += Hex(hashvalue(i)).ToLower
                Next
        End Select
    End Function
    Function EncodeBase64(ByVal StrA)
        Dim BufferA As Byte()
        BufferA = System.Text.Encoding.Default.GetBytes(StrA)
        Dim StrB As String
        StrB = Convert.ToBase64String(BufferA)
        EncodeBase64 = StrB
    End Function
    Function DecodeBase64(ByVal StrA)
        DecodeBase64 = Encoding.GetEncoding("gb2312").GetString(Convert.FromBase64String(StrA))
    End Function
    Function PassPortCheck()
        Dim connstr, connA, rsA
        connstr = ConfigurationSettings.AppSettings("SQLConnString") & """" & Server.MapPath(".") & "\..\" & ConfigurationSettings.AppSettings("dbPath") & """"
        connA = Server.CreateObject("ADODB.Connection")
        connA.open(connstr)
        Dim Admin_UserName, Admin_UserPass
        Admin_UserName = replace(Request.Cookies("TaoddAdmin").value, "'", "''")
        Admin_UserPass = replace(Request.Cookies("TaoddPassWord").value, "'", "''")
        rsA = Server.CreateObject("adodb.recordset")
        rsA.open("select * from [admin^] where Admin_UserName='" & Admin_UserName & "' and Admin_UserPass='" & Admin_UserPass & "'", connA, 1, 3)
        If rsA.eof Then
            Response.Redirect("login.aspx")
        End If
        connA.close()
        connA = Nothing
    End Function


   


    Public Shared Function MD5x(ByVal strSource As String, ByVal Code As Int16) As String
        '这里用的是ascii编码密码原文，如果要用汉字做密码，可以用UnicodeEncoding，但会与ASP中的MD5函数不兼容 
        Select Case Code
            Case 16 '´选择16位字符的加密结果 
                MD5x = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "MD5").ToLower().Substring(8, 16)
            Case 32 ' ´选择32位字符的加密结果 
                MD5x = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "MD5").ToLower()
        End Select
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        If Request.Cookies("TaoddAdmin") Is Nothing Or Request.Cookies("TaoddPassWord") Is Nothing Then
            Response.Redirect("login.aspx")
        Else
            PassPortCheck()
        End If



        If Request("Action") = "GetShopList" Then
            GetShopList()
        End If
        If Request("Action") = "PutShopInfo" Then
            PutShopInfo()


            Response.End()
        End If

    End Sub
    Function getstr(ByVal iRemote)
        Dim xPost, sGet
        xPost = Server.CreateObject("msxml2.serverxmlhttp") 'msxml2.serverxmlhttp
        xPost.Open("GET", iRemote, False)
        xPost.setrequestheader("referer", "http://taoke.alimama.com/spreader/search_sh_catalog.htm")
        xPost.Send()
        sGet = CreateObject("ADODB.Stream")
        sGet.Mode = 3
        sGet.Type = 1
        sGet.Open()
        On Error Resume Next
        If Err.Number > 0 Then
            Response.Write(iRemote)
        End If
        sGet.Write(xPost.responseBody)

        sGet.Position = 0
        sGet.Type = 2
        sGet.Charset = "gb2312" ' "gb2312"
        getstr = sGet.ReadText
    End Function
    Function PutShopInfo()
        'Exit Function
        On Error Resume Next
        Dim rs, re, shopCount, shopurl, htmlcode, shopdate, shophaoping, xiaobao, spurl, shouchangrenqi, spcode, xiaobaocode, GoodsCount
        rs = Request("rs")
        re = Request("re")
        Dim connstr, conn, shopidA
        connstr = ConfigurationSettings.AppSettings("SQLConnString") & """" & Server.MapPath(".") & "\..\" & ConfigurationSettings.AppSettings("dbPath") & """"
        conn = Server.CreateObject("ADODB.Connection")
        conn.open(connstr)
        shopCount = Request("Count")
        If Request("Count") = "" Then shopCount = 100
        If Request("re") = "" Then re = 200
        If Request("rs") = "" Then rs = 1


        If Request("shopid") <> "" Then
            shopurl = "http://shop" & Request("shopid") & ".taobao.com/"
         
            htmlcode = getstr(shopurl & "?rnd=" & Rnd())
            'Response.Write(htmlcode)
            'Response.End()
            GoodsCount = gethtml(htmlcode, "><span>宝贝数量：</span>", "</li>", -1)
            If GoodsCount = "" Then GoodsCount = 0
            If InStr(htmlcode, "没有找到相应的店铺信息") Or Int(GoodsCount) = 0 Then
                rs = Server.CreateObject("adodb.recordset")
                shopidA = LCase(Request("shopid"))
                shopidA = Replace(shopidA, "shop", "")
                rs.open("select *  from url where shopid='" & Int(shopidA) & "'", conn, 2, 3)
                If Not rs.eof Then
                    rs.delete()
                    rs.update()
                    rs.close()
                    conn.close()
                    rs = Nothing
                    conn = Nothing
                End If
                Response.Write("Null")
                Response.End()
            End If
            shopdate = Replace(gethtml(htmlcode, "创店时间：</span>", "</li>", -1), vbTab, "") '创店时间
            If InStr(htmlcode, "<span>好评率：</span><strong>") > 0 Then
                shophaoping = gethtml(htmlcode, "<span>好评率：</span><strong>", "%</strong>", -1) '卖家好评率
            Else
                shophaoping = gethtml(htmlcode, "<li><span>卖家好评率：</span><strong>", "</strong></li>", -1) '卖家好评率
            End If
            If shophaoping = "" Then
                shophaoping = gethtml(htmlcode, "<em>(好评率:", "%)</em>", -1) '卖家好评率
            End If
            shopdate = Replace(shopdate, vbNewLine, "") '创店时间2
            ' shopAddress=  gethtml(htmlcode,"创店时间：</span>","</li>")
            xiaobao = gethtml(htmlcode, "<h3>掌柜档案</h3>", "<span>收藏本店铺</span>", -1) '是否加入消保1
            If InStr(xiaobao, "title=""已加入消费者保障服务""") Then
                xiaobao = "已加入消费者保障服务"
            Else
                xiaobao = ""
            End If

            'spurl = gethtml(htmlcode, "<div class=""bd"">", "</div>", -1) '得到一件商品的地址A

            spurl = gethtml(htmlcode, "auction/item_detail-", ".", -1) ' 得到一件商品的地址B
            If spurl = "" Then
                'spurl = gethtml(htmlcode, "item.htm?id=", """>", -1)
                spurl = Right(htmlcode, Len(htmlcode) - InStrRev(htmlcode, "item.htm?id=") - 11)
                If InStr(spurl, "'") > InStr(spurl, """") Then
                    spurl = Left(spurl, InStr(spurl, """") - 1)
                Else
                    spurl = Left(spurl, InStr(spurl, "'") - 1)
                End If
                spurl = "http://item.taobao.com/item.htm?id=" & spurl
            Else
                spurl = "http://item.taobao.com/auction/item_detail-" & spurl & ".htm" '得到一件商品的地址c
            End If
     
            shouchangrenqi = 0

            'if instr(spcode,"<span>收藏人气：</span>") then 
            'shouchangrenqi=gethtml(spcode,"<span>收藏人气：</span>","&nbsp",-1)
            'end if
            'response.Write(spurl)
            'response.End()
            spcode = getstr(spurl)
            'response.End()
            Dim rsms, qtth, jyps, sstwx, sdfh, zpbz, shopAddress, shopxinyong, shopmaster, shopdengji, shopdengjiB, shopdengjipic
            Dim shopclass, urlcode, shopid, commissionRate
            ' Response.Write(spurl)
            'Response.End()
            If shophaoping = "" Then shophaoping = gethtml(spcode, "<span>好评率：</span>", "%</li>", -1)
            xiaobaocode = gethtml(spcode, "<span>特色服务：</span>", "如未履行，淘宝网将按", -1) '得到消保详细信息A

            If InStr(xiaobaocode, "如实描述") Then rsms = "如实描述" : xiaobao = "已加入消费者保障服务"
            If InStr(xiaobaocode, "7天退换") Then qtth = "7天退换" : xiaobao = "已加入消费者保障服务"
            If InStr(xiaobaocode, "假一赔三") Then jyps = "假一赔三" : xiaobao = "已加入消费者保障服务"
            If InStr(xiaobaocode, "30天维修") Then sstwx = "30天维修" : xiaobao = "已加入消费者保障服务"
            If InStr(xiaobaocode, "闪电发货") Then sdfh = "闪电发货" : xiaobao = "已加入消费者保障服务"
            If InStr(xiaobaocode, "正品保障") Then zpbz = "正品保障" : xiaobao = "已加入消费者保障服务"


            If InStr(htmlcode, "<span>地址：</span>") Then
                shopAddress = Replace(gethtml(htmlcode, "<span>地址：</span>", "</li>", -1), vbTab, "") '卖家地址
                shopAddress = Replace(shopAddress, vbNewLine, "")
                If shophaoping = "" Then
                    shophaoping = gethtml(htmlcode, "<li><span>卖家好评率：</span><strong>", "</strong></li>", -1) '卖家好评率
                End If
            Else
                shopAddress = Replace(gethtml(htmlcode, "<span>所在地区：</span>", "</li>", -1), vbTab, "") '卖家地址
                shopAddress = Replace(shopAddress, vbNewLine, "")

                '  shophaoping = gethtml(spcode, "<span>卖家好评率：</span>", "</li>", -1)
            End If
            '  shopxinyong = gethtml(htmlcode, "<span>卖家信用：</span>", "/a>", -1) '卖家信用1
            ' shopxinyong = gethtml(shopxinyong, """>", "<", -1) '卖家信用2
            shopmaster = gethtml(htmlcode, "class=""hCard fn"">", "</a>", -1) '掌柜
            shopdengji = gethtml(htmlcode, ".htm"">" & shopxinyong & "</a>", "class=""rank""", -1) '店铺等级1
            'if shopxinyong<>"" and shopdengji="" then
            'response.Write "<script>alert('xx')</script>"
            ' end if
            'If shopxinyong = "" Then shopxinyong = "0"
            If InStr(htmlcode, "<h3><span>商家信息</span></h3>") Then

                shopxinyong = "-1"
            End If
            Dim rateurl, ratecode
            
            If shopxinyong = "" Then
                ' rateurl = gethtml(htmlcode, "http://rate.taobao.com/user-rate-", ".htm", -1)
                ratecode = getstr("http://taoke.alimama.com/spreader/adShopList.htm?shopKeeperID=" & Request.QueryString("shopKeeperID"))
                ' shopxinyong = gethtml(ratecode, "#RateType"" >" & vbNewLine & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & vbTab & vbTab & vbTab & vbTab, vbNewLine & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & Space(1) & vbTab & vbTab & vbTab & "</a>", -1)
                shopxinyong = gethtml(ratecode, "=getRank(", ",""", -1)
                shopAddress = gethtml(ratecode, "<strong>掌柜地址：</strong>", "</li>", -1)
          
            End If
            shopAddress = Replace(shopAddress, vbNewLine, "")
            shopAddress = Replace(shopAddress, vbTab, "")

            
            shopxinyong = Int(shopxinyong) 'd
            If shopxinyong = -1 Then
                shopdengjiB = "商城"
                shopdengjipic = "images/store.gif"
            End If
            If shopxinyong >= 4 And shopxinyong <= 10 Then
                shopdengjiB = "一星"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_red_1.gif"
            End If
            If shopxinyong >= 11 And shopxinyong <= 40 Then
                shopdengjiB = "双星"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_red_2.gif"
            End If
            If shopxinyong >= 41 And shopxinyong <= 90 Then
                shopdengjiB = "三星"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_red_3.gif"
            End If
            If shopxinyong >= 91 And shopxinyong <= 150 Then
                shopdengjiB = "四星"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_red_4.gif"
            End If
            If shopxinyong >= 151 And shopxinyong <= 250 Then
                shopdengjiB = "五星"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_red_5.gif"
            End If
            If shopxinyong >= 251 And shopxinyong <= 500 Then
                shopdengjiB = "一钻"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_blue_1.gif"
            End If
            If shopxinyong >= 501 And shopxinyong <= 1000 Then
                shopdengjiB = "双钻"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_blue_2.gif"
            End If
            If shopxinyong >= 1001 And shopxinyong <= 2000 Then
                shopdengjiB = "三钻"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_blue_3.gif"
            End If
            If shopxinyong >= 2001 And shopxinyong <= 5000 Then
                shopdengjiB = "四钻"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_blue_4.gif"
            End If
            If shopxinyong >= 5001 And shopxinyong <= 10000 Then
                shopdengjiB = "五钻"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_blue_5.gif"
            End If
            If shopxinyong >= 10001 And shopxinyong <= 20000 Then
                shopdengjiB = "一冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_cap_1.gif"
            End If
            If shopxinyong >= 20001 And shopxinyong <= 50000 Then
                shopdengjiB = "双冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_cap_2.gif"
            End If
            If shopxinyong >= 50001 And shopxinyong <= 100000 Then
                shopdengjiB = "三冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_cap_3.gif"
            End If
            If shopxinyong >= 100001 And shopxinyong <= 200000 Then
                shopdengjiB = "四冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_cap_4.gif"
            End If
            If shopxinyong >= 200001 And shopxinyong <= 500000 Then
                shopdengjiB = "五冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_cap_5.gif"
            End If
            If shopxinyong >= 500001 And shopxinyong <= 1000000 Then
                shopdengjiB = "一金冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_crown_1.gif"
            End If
            If shopxinyong >= 1000001 And shopxinyong <= 2000000 Then
                shopdengjiB = "双金冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_crown_2.gif"
            End If
            If shopxinyong >= 2000001 And shopxinyong <= 5000000 Then
                shopdengjiB = "三金冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_crown_3.gif"
            End If
            If shopxinyong >= 5000001 And shopxinyong <= 10000000 Then
                shopdengjiB = "四金冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_crown_4.gif"
            End If
            If shopxinyong > 10000000 Then
                shopdengjiB = "五金冠"
                shopdengjipic = "http://pics.taobaocdn.com/newrank/s_crown_5.gif"
            End If

            htmlcode = getstr("http://taoke.alimama.com/spreader/gen_shop_code.htm?pid=" & Request("shopKeeperID") & "&rnd=" & Rnd())

            'shopname =  replace(gethtml(htmlcode,"single_pro_name""> 店铺名称: ","</dd>",-1),vbtab,"") '店铺名称
            shopclass = gethtml(htmlcode, "single_pro_name"">店铺分类: ", "</dd>", -1) '店铺名称
            urlcode = gethtml(htmlcode, "txt_urlcode"" name=""foroverflow"">", "</textarea>", -1) '店铺推广连接
            If InStr(urlcode, "=mm_") Then
                urlcode = Replace(urlcode, "10011550", "Pid")
            Else
                urlcode = Left(urlcode, InStrRev(urlcode, "-"))
            End If
          
          

            'htmlcode = getstr("http://taoke.alimama.com/spreader/cps_cat_commission_rate.do?shopKeeperID=" & Request("shopKeeperID") & "&rnd=" & Rnd())
            'commissionRate = gethtml(htmlcode, "commissionRate"":", ",""", -1) '店铺名称
            ' shopclass = gethtml(htmlcode, "catName"":""", """}", -1) '店铺名称
            shopclass = Request("catname")
            If urlcode = "" Then urlcode = "NULL"
            shopid = Replace(Request("shopid"), "'", "'")
            rs = Server.CreateObject("adodb.recordset")

            rs.open("select *  from url where shopid='" & shopid & "'", conn, 2, 3)

            If Not rs.eof Then
                rs("SHOPURL").value = urlcode
                rs("EXLEVEL").value = shopdengjiB
                rs("shopAddress").value = Trim(shopAddress)
                rs("shopCredit").value = shopxinyong
                shophaoping = Replace(shophaoping, "%", "")
                rs("shopEvaluation").value = shophaoping
                rs("shopCreation").value = shopdate
                rs("shopclass").value = shopclass
                rs("xiaobao").value = xiaobao
                'rs("Favorites")=shouchangrenqi
                If qtth <> "" Then rs("qtth").value = True
                If jyps <> "" Then rs("jyps").value = True
                If sstwx <> "" Then rs("sstwx").value = True
                If sdfh <> "" Then rs("sdfh").value = True
                If zpbz <> "" Then rs("zpbz").value = True
                If rsms <> "" Then rs("rsms").value = True
                rs("Debris").value = False
                rs.update()




            End If
            rs.close()
            conn.close()
            Response.Write(shopAddress & "|" & shopclass & "|shopaddressAndclass")



            Response.End()
        End If
    End Function
    Function GetShopList()
        Dim url, a, catid, tempcode, pagescount, searchCataName, totalnum, i, pic, dj, shopid
        Dim connstr, conn, rs
        connstr = ConfigurationSettings.AppSettings("SQLConnString") & """" & Server.MapPath(".") & "\..\" & ConfigurationSettings.AppSettings("dbPath") & """"
        conn = Server.CreateObject("ADODB.Connection")
        conn.open(connstr)
        Randomize()
        ReDim shopArray(20, 11)
        catid = Request("catid")
        If Request("catid") = "" Then catid = "14"
        url = "http://taoke.alimama.com/spreader/search_shop_from_engine.do?_input_charset=gb2312&od=" & Request("od") & "&catid=" & catid & "&p=" & Request("p") & "&coms=" & Request("coms") & "&come=" & Request("come") & "&crs=" & Request("crs") & "&cre=" & Request("cre") & "&hs=" & Request("hs") & "&he=" & Request("he") & "&mid=" & Session("mid") & "&rnd=" & Rnd()
        tempcode = getstr(url)
        'response.Write(url)
        a = gethtml(tempcode, ",""TITLE"":""", """}", 0)  '店铺名称
        a = gethtml(tempcode, """CONTACT"":""", """,""ORIMEMBERID"":", 1)  '店铺主人
        a = gethtml(tempcode, ",""SHOPURL"":""", """,""ISCPS"":", 2) '店铺网址
        a = gethtml(tempcode, ",""EXLEVEL"":""", """,""STATUS"":", 3) '店铺等级
        a = gethtml(tempcode, """,""MEMBERID"":""", """,""SHOPTYPE"":", 4) '店铺ID
        a = gethtml(tempcode, """,""PICTURL"":""", """,""CATNAME"":""", 5) '店铺店标
        a = gethtml(tempcode, ",""AUCTIONCOUNT"":""", """,""TOTALACTION"":", 6) '商品总量
        a = gethtml(tempcode, """,""TOTALACTION"":""", """,""SORTRANK"":", 7) '累计推广量
        a = gethtml(tempcode, """COMMISSIONRATE"":""", """,""RANK_SCORE"":", 8) '佣金比例*0.01
        a = gethtml(tempcode, """ORIMEMBERID"":""", """,""EXSYSTYPE"":", 11) '佣金比例*0.01
        pagescount = gethtml(tempcode, ",""max"":", ",""cur"":", 9) '当前分类总页数
        searchCataName = gethtml(tempcode, "searchCataName"":""", """}", 10) '当前分类名字
        totalnum = gethtml(tempcode, "totalnum"":", ",""type"":", 10) '当前分类名字
        tempcode = ""
        For i = 0 To 19
            If shopArray(i, 4) <> "" Then
                If (i) < Int(Request("Count") + 1) Then
                    Select Case (shopArray(i, 3))
                        Case 1
                            pic = "http://image.taobao.com/helpcenter/xin1.gif"
                            dj = "一星"
                        Case 2
                            pic = "http://image.taobao.com/helpcenter/xinxin2.gif"
                            dj = "二星"
                        Case 3
                            pic = "http://image.taobao.com/helpcenter/xinxin3.gif"
                            dj = "三星"
                        Case 4
                            pic = "http://image.taobao.com/helpcenter/xinxin4.gif"
                            dj = "四星"
                        Case 5
                            pic = "http://image.taobao.com/helpcenter/xinxin5.gif"
                            dj = "五星"
                        Case 11
                            pic = "http://image.taobao.com/helpcenter/xinxin1.gif"
                            dj = "一钻"
                        Case 12
                            pic = "http://image.taobao.com/helpcenter/xin2.gif"
                            dj = "二钻"
                        Case 13
                            pic = "http://image.taobao.com/helpcenter/xin3.gif"
                            dj = "三钻"
                        Case 14
                            pic = "http://image.taobao.com/helpcenter/xin4.gif"
                            dj = "四钻"
                        Case 15
                            pic = "http://image.taobao.com/helpcenter/xin5.gif"
                            dj = "五钻"
                        Case 101
                            pic = "http://image.taobao.com/newrank/s_cap_1.gif"
                            dj = "一冠"
                        Case 102
                            pic = "http://image.taobao.com/newrank/s_cap_2.gif"
                            dj = "二冠"
                        Case 103
                            pic = "http://image.taobao.com/newrank/s_cap_3.gif"
                            dj = "三冠"
                        Case 104
                            pic = "http://image.taobao.com/newrank/s_cap_4.gif"
                            dj = "四冠"
                        Case 105
                            pic = "http://image.taobao.com/newrank/s_cap_5.gif"
                            dj = "五冠"
                        Case Else
                            pic = "Unknown"
                    End Select

                    If shopArray(i, 5) = "http://logo.taobao.com/shop-logo/" And shopArray(i, 3) = "0" Then
                        pic = "../images/store.gif"
                        dj = "商城商家"
                    End If
                    shopid = Replace(shopArray(i, 2), "http://shop", "")
                    shopid = Replace(shopid, ".taobao.com/", "")
                    If InStr(shopid, ".") Then shopid = Left(shopid, InStr(shopid, ".") - 1)
                    tempcode = tempcode & shopArray(i, 1) & "," & shopid & "," & shopArray(i, 4) & "," & Request("catname") & "," & shopArray(i, 11) & "@"
                    rs = Server.CreateObject("adodb.recordset")
                    rs.open("select *  from url where shopid='" & shopid & "'", conn, 2, 3)
                    If rs.eof Then
                        rs.addnew()
                        rs("shopid").value = shopid
                        rs("catid").value = catid
                        rs("Url_Name").value = shopArray(i, 0)
                        rs("Url_Url").value = shopArray(i, 2)
                        rs("PICTURL").value = shopArray(i, 5)
                        rs("MEMBERID").value = shopArray(i, 4)
                        rs("EXLEVEL").value = dj
                        rs("CONTACT").value = shopArray(i, 1)
                        rs("commissionRate").value = shopArray(i, 8) * 0.01
                        rs("TOTALACTION").value = shopArray(i, 7)
                        rs("Debris").value = True
                        rs.update()
                        rs.close()
                    End If

                End If
            End If
        Next

        conn.close()

        If tempcode = "" Then
            tempcode = "Null"
        Else
            If Right(tempcode, 1) = "@" Then tempcode = Left(tempcode, Len(tempcode) - 1)
        End If

        Response.Write(tempcode)
        Response.End()
    End Function



    Function gethtml(ByVal tmp, ByVal s, ByVal e, ByVal id)
        Dim String1, String2, j, arrstr
        'on error resume next
        String1 = s
        String2 = e
        Dim fbegin
        Dim fend
        fbegin = 1
        fend = 1
        j = 0
        Do
            fbegin = InStr(fbegin, tmp, String1)
            If fbegin = 0 Then Exit Function
            fend = InStr(fbegin, tmp, String2)
            If fend = 0 Then Exit Function
            arrstr = Mid(tmp, fbegin + Len(String1), fend - (fbegin + Len(String1)))
            If Int(id) >= 0 Then
                shopArray(j, id) = arrstr
                j = j + 1
            End If

            gethtml = arrstr
            If Int(id) = -1 Then Exit Function

            If s = "<div class=""bd"">" Then
                If InStr(arrstr, "http://item.taobao.com/auction/item_detail-") Then
                    Exit Function
                End If
            End If
            fbegin = fend + Len(String2)
        Loop While True
    End Function

End Class
